<script>
	import {mapMutations} from 'vuex'
	import pageAnimation from '@/components/page-animation'
	import {isEmpty} from '@/common/graceChecker.js'
	import _GENV from '@/common/env.js'
	// import {wexinshare} from '@/common/wechatshare.js';
	function goweixin(that){
		//开发环境调试,上线务必将以下注释
		//请把有效的token复制到下面
		// uni.setStorageSync('token','’eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhaS50dC5jb20iLCJhdWQiOiJpY29uX3BxcF9wIiwiaWF0IjoxNjI5MTAwOTY4LCJleHAiOjE2MjkxMTE3NjgsInVpZCI6Im85SElGajdlYS1YcUZnMVM1cjBJRWJYa2wyRkEifQ.xp8j9z-qD6KNGWvQIprKBuwyGEaV1tkuQKbg5fIdy04')
		// window.location.replace('http://localhost:8080/h5/?code=xxxx&state=123#/pages/user/user');
		// return
		//END
		var local = that.weixinhttpurl+'/#/pages/shouquan/shouquan'; // 获取页面url
			var appid = _GENV.GwechatAppid;
			var href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(
		local
		)}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`;	
			window.location.replace(href);
			return;
	}
	export default {
		mixins: [pageAnimation],
		onLaunch: function(e) {
			let that=this;
			console.log(e)
			let showpath=e.path;
				sessionStorage.setItem("httpshowpath",showpath);
					 if(showpath =='pages/article/iostest'||showpath =='pages/message/messagecenter'||showpath =='pages/yaoqing/fangxiang'||showpath =='pages/Departmentmanagement/sharedepartment'){
						var thisquery="";
						if(e.query){					
							var person = e.query;
							let info;
							let num=0;
							for(info in person) {
								if(num==0){
									thisquery+='?'+info+'='+person[info];
								}else{
									thisquery+='&'+info+'='+person[info];
								} 
								
								if(info=='sharecode'){
									var sharecode=person[info];
									sessionStorage.setItem("sharecode",sharecode);
								}
							num++;
							
							}
						}
						sessionStorage.setItem("locationhref",showpath+thisquery);
						sessionStorage.setItem("thispath",showpath);
						localStorage.setItem('localurl',showpath+thisquery)
						var skippagesession=sessionStorage.getItem("skippagesession");
						// uni.setStorageSync('token','test');						
						if(!skippagesession){
							sessionStorage.setItem("skippage",'YES')
							sessionStorage.setItem("skippagesession",'YES')
							 goweixin(that)
						 }
					}else if(showpath =='pages/shouquan/shouji'||showpath =='pages/shouquan/shengfen'){ //跳转登录
							
					}else if(showpath !='pages/shouquan/shouquan'){				
						// uni.setStorageSync('locationhref',e)
						var thisquery="";
						if(e.query){					
							var person = e.query;
							let info;
							let num=0;
							for(info in person) {
								if(num==0){
									thisquery+='?'+info+'='+person[info];
								}else{
									thisquery+='&'+info+'='+person[info];
								} 
								
								if(info=='sharecode'){
									var sharecode=person[info];
									sessionStorage.setItem("sharecode",sharecode);
								}
							num++;
							
							}
						}
						sessionStorage.setItem("locationhref",showpath+thisquery);
						sessionStorage.setItem("thispath",showpath);
							
						var thistoken=sessionStorage.getItem("tokensession");
						
						if(!thistoken){ //判断是第一次没有登录跳转登录 e.path=='pages/yaoqing/fangxiang'
							//跳过绑定
							goweixin(that)
						}else{
							
						}
					}
					
			let userInfo = uni.getStorageSync('userInfo')
			if(!isEmpty(userInfo)){
				uni.getStorage({
				    key: 'userInfo',
				    success: res=> {
						this.login(res.data)
				    }
				});
			}	
		},
		
		onShow: function() {
			console.log('App Show');
			// var title="欢迎您使用-访客系统";
			// let desccontent='访客系统-Power by 中山协成科技有限公司';
			// var url=this.weixinhttpurl;
			// var img=this.sharehttpurl+'/public/static/images/logoshare.png';
			// var sharedata={
			// 	title:title,
			// 	desc:desccontent,
			// 	img:img,
			// 	link:url
			// }
			// wexinshare(sharedata)//微信分享
		},
		onHide: function() {
			console.log('App Hide');
		},
		methods:{
			...mapMutations(['login']),
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* uni-app默认全局使用flex布局。因为flex布局有利于跨更多平台，尤其是采用原生渲染的平台。如不了解flex布局，请参考http://www.w3.org/TR/css3-flexbox/。如不使用flex布局，请删除或注释掉本行。*/
	body,
	page {
		min-height: 100%;
		display: flex;
	}

	/* #ifdef MP-BAIDU */
	page {
		width: 100%;
		height: 100%;
		display: block;
	}

	swan-template {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* 原生组件模式下需要注意组件外部样式 */
	custom-component {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* #endif */

	/* 原生组件模式下需要注意组件外部样式 */
	m-input {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	
	.uni-input {
		height: 25px;
		padding: 7px 12px;
		line-height: 25px;
		font-size: 14px;
		/* background: #FFF; */
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		-ms-flex: 1;
		flex: 1;
	}

	.input-group {
		background-color: #ffffff;
		margin-top: 28upx;
		position: relative;
	}

	.input-group::before {
		position: absolute;
		right: 0;
		top: 0;
		left: 0;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	.input-group::after {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}
	
	.input-row {
		display: flex;
		flex-direction: row;
		position: relative;
	}

	.input-row .title {
		width: 22%;
		height: 50upx;
		min-height: 50upx;
		padding: 20upx 0;
		padding-left: 30upx;
		line-height: 50upx;
	}

	.input-row.border::after {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 15upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	} 

	.btn-row {
		margin-top: 50upx;
		padding: 20upx;
	}
	
	button.primary {
		background-color: #0faeff;
	}
	.an-user-image3{
			
			width: 100upx;
			height: 100upx;
			border-radius: 50%;
			overflow: hidden;
			position: absolute;
			margin-top: 10px;
			
			
		}
		.an-user-image3 image{
			width: 100upx; 
			height: 100upx; 
			background-color: #eeeeee;
		}
		
		uni-toast .uni-toast__content{font-size: 14px;}
		.radioall uni-radio .uni-radio-input{width: 18px;height: 18px;}
		
		.statusInformation {
			width: 95%;
			margin: auto;
			}
		.statusInformation .status-information {
				display: flex;
				margin: 0px 0;
				padding: 5px 0px;
				background-color: #fff;
				border-bottom: 1px solid #eee;
				
			}
		.statusInformation .statusEND{padding-bottom:10px;border-bottom: 1px solid #9e9e9e;}
</style>